package com.yangrui.app.mapper;

import com.yangrui.app.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

@Repository
public interface UserMapper {

    /**
     * 插入数据
     * @param user user
     * @return 响应值
     */

    @Insert("insert into lesson.user(username, password, real_name, gender, avatar, phone)" +
            "values(#{username},#{password},#{realName},#{gender},#{avatar},#{phone})")
    int insert(User user);

    /**
     * 根据用户名查询
     * @param username 用户名
     * @return user
     */
    @Select("select id,username,password,real_name,gender,avatar,phone,create_time from user where username=#{param1}")
    User selectByUsername(String username);

    /**
     * 根据主键查询
     * @param id id
     * @return user
     */
    @Select("SELECT id,username,password,real_name,gender,avatar,phone,create_time FROM user where id=#{param1}")
    User selectById(Integer id);

    /**
     *  根据主键修改
     * @param user user
     * @return 1
     */
    @Update("UPDATE lesson.user SET  password = #{password}, real_name = #{realName}, gender = #{gender}, avatar = #{avatar}, phone = #{phone} WHERE id = #{id}")
    int updateById(User user);

    /**
     *  根据主线删除
     * @param id id
     * @return 1
     */
    @Delete("delete from lesson.user where id=#{param1}")
    int deleteById(Integer id);
}
